﻿//JumbotCms_4.1 Final
using System;
using System.Web;
using System.Data;

namespace JumbotCms.DataObject
{
    /// <summary>
    /// 站点配置表信息
    /// </summary>
    public class Site
    {
        private string m_Name;
        private string m_Url;
        private string m_Dir;
        private bool m_IsOpen;
        private string m_CloseMessage;
        private int m_PageCount = 0;
        private string m_TitleTail;
        private string m_Keywords;
        private string m_Description;
        private bool m_IsTiming;
        private string m_OpenTime;
        private bool m_IsHtml;
        private bool m_AllowReg;
        private bool m_OnlyEmail;
        private bool m_CheckReg;
        private string m_StaticExt;
        private string m_ICP;
        private string m_UserItem;
        private string m_WriterItem;
        private string m_Service;
        private int m_AdminGroupId = 0;
        private string m_CookieDomain;
        private string m_CookiePath;
        private string m_CookiePrev;
        private string m_CookieKeyCode;
        private bool m_UrlReWriter = true;
        private bool m_ExecuteSql = false;
        private int m_CreatePages = 20;
        private string m_ForumPath;
        private string m_ForumUrl;
        private string m_LoginUrl;
        private string m_LogoutUrl;
        private string m_RegisterUrl;
        private string m_GetPasswordUrl;
        //用于调试的key
        private string m_DebugKey;

        /// <summary>
        /// 网站名称
        /// </summary>
        public string Name
        {
            set { m_Name = value; }
            get { return m_Name; }
        }
        /// <summary>
        /// 网站地址
        /// </summary>
        public string Url
        {
            set { m_Url = value; }
            get { return m_Url; }
        }
        /// <summary>
        /// 安装目录
        /// </summary>
        public string Dir
        {
            set { m_Dir = value; }
            get { return m_Dir; }
        }
        /// <summary>
        /// 是否打开
        /// </summary>
        public bool IsOpen
        {
            set { m_IsOpen = value; }
            get { return m_IsOpen; }
        }
        /// <summary>
        /// 关闭时的公告语
        /// </summary>
        public string CloseMessage
        {
            set { m_CloseMessage = value; }
            get { return m_CloseMessage; }
        }
        /// <summary>
        /// 标题尾巴
        /// </summary>
        public string TitleTail
        {
            set { m_TitleTail = value; }
            get { return m_TitleTail; }
        }
        /// <summary>
        /// 关键字
        /// </summary>
        public string Keywords
        {
            set { m_Keywords = value; }
            get { return m_Keywords; }
        }
        /// <summary>
        /// 网站描述
        /// </summary>
        public string Description
        {
            set { m_Description = value; }
            get { return m_Description; }
        }
        /// <summary>
        /// 定时打开
        /// </summary>
        public bool IsTiming
        {
            set { m_IsTiming = value; }
            get { return m_IsTiming; }
        }
        /// <summary>
        /// 定时开关的时间
        /// </summary>
        public string OpenTime
        {
            set { m_OpenTime = value; }
            get { return m_OpenTime; }
        }
        /// <summary>
        /// 是否静态
        /// </summary>
        public bool IsHtml
        {
            set { m_IsHtml = value; }
            get { return m_IsHtml; }
        }
        /// <summary>
        /// 允许注册
        /// </summary>
        public bool AllowReg
        {
            set { m_AllowReg = value; }
            get { return m_AllowReg; }
        }
        /// <summary>
        /// 一个Email注册一次
        /// </summary>
        public bool OnlyEmail
        {
            set { m_OnlyEmail = value; }
            get { return m_OnlyEmail; }
        }
        /// <summary>
        /// 注册需要审核
        /// </summary>
        public bool CheckReg
        {
            set { m_CheckReg = value; }
            get { return m_CheckReg; }
        }
        /// <summary>
        /// 默认每页记录
        /// </summary>
        public int PageCount
        {
            set { m_PageCount = value; }
            get { return m_PageCount; }
        }
        /// <summary>
        /// 静态后缀
        /// </summary>
        public string StaticExt
        {
            set { m_StaticExt = value; }
            get { return m_StaticExt; }
        }
        /// <summary>
        /// 备案号
        /// </summary>
        public string ICP
        {
            set { m_ICP = value; }
            get { return m_ICP; }
        }
        /// <summary>
        /// User项目名
        /// </summary>
        public string UserItem
        {
            set { m_UserItem = value; }
            get { return m_UserItem; }
        }
        /// <summary>
        /// Writer项目名
        /// </summary>
        public string WriterItem
        {
            set { m_WriterItem = value; }
            get { return m_WriterItem; }
        }
        /// <summary>
        ///技术支持
        /// </summary>
        public string Service
        {
            set { m_Service = value; }
            get { return m_Service; }
        }
        /// <summary>
        /// 管理员组的编号
        /// </summary>
        public int AdminGroupId
        {
            set { m_AdminGroupId = value; }
            get { return m_AdminGroupId; }
        }
        /// <summary>
        /// Cookie作用域
        /// </summary>
        public string CookieDomain
        {
            set { m_CookieDomain = value; }
            get { return m_CookieDomain; }
        }
        /// <summary>
        /// Cookie作用路径
        /// </summary>
        public string CookiePath
        {
            set { m_CookiePath = value; }
            get { return m_CookiePath; }
        }
        /// <summary>
        /// Cookie前缀
        /// </summary>
        public string CookiePrev
        {
            set { m_CookiePrev = value; }
            get { return m_CookiePrev; }
        }
        /// <summary>
        /// Cookie加密密钥
        /// </summary>
        public string CookieKeyCode
        {
            set { m_CookieKeyCode = value; }
            get { return m_CookieKeyCode; }
        }
        /// <summary>
        /// 是否启用伪静态
        /// </summary>
        public bool UrlReWriter
        {
            set { m_UrlReWriter = value; }
            get { return m_UrlReWriter; }
        }
        /// <summary>
        /// 可以在线执行SQL
        /// </summary>
        public bool ExecuteSql
        {
            set { m_ExecuteSql = value; }
            get { return m_ExecuteSql; }
        }
        /// <summary>
        /// 默认缓存的页数
        /// </summary>
        public int CreatePages
        {
            set { m_CreatePages = value; }
            get { return m_CreatePages; }
        }
        /// <summary>
        /// 论坛安装路径
        /// </summary>
        public string ForumPath
        {
            set { m_ForumPath = value; }
            get { return m_ForumPath; }
        }
        /// <summary>
        /// 论坛链接地址
        /// </summary>
        public string ForumUrl
        {
            set { m_ForumUrl = value; }
            get { return m_ForumUrl; }
        }
        /// <summary>
        /// 登入链接地址
        /// </summary>
        public string LoginUrl
        {
            set
            {
                if (value.StartsWith("http://"))
                    m_LoginUrl = value;
                else
                    m_LoginUrl = this.Dir + value;
            }
            get { return m_LoginUrl; }
        }
        /// <summary>
        /// 登出链接地址
        /// </summary>
        public string LogoutUrl
        {
            set
            {
                if (value.StartsWith("http://"))
                    m_LogoutUrl = value;
                else
                    m_LogoutUrl = this.Dir + value;
            }
            get { return m_LogoutUrl; }
        }
        /// <summary>
        /// 注册链接地址
        /// </summary>
        public string RegisterUrl
        {
            set
            {
                if (value.StartsWith("http://"))
                    m_RegisterUrl = value;
                else
                    m_RegisterUrl = this.Dir + value;
            }
            get { return m_RegisterUrl; }
        }
        /// <summary>
        /// 找回密码地址
        /// </summary>
        public string GetPasswordUrl
        {
            set
            {
                if (value.StartsWith("http://"))
                    m_GetPasswordUrl = value;
                else
                    m_GetPasswordUrl = this.Dir + value;
            }
            get { return m_GetPasswordUrl; }
        }
        /// <summary>
        /// 用于调试的Key
        /// </summary>
        public string DebugKey
        {
            set { m_DebugKey = value; }
            get { return m_DebugKey; }
        }
        public Site()
        { }

        public Site(Jumbot.DataOper.DbOperHandler doh)
        {
            doh.Reset();
            object[] _obj = doh.GetValues("jcms_normal_system", "Info");
            string[] temp = _obj[0].ToString().Split('§');
            Name = temp[0];
            IsOpen = temp[1] == "1";
            CloseMessage = temp[2];
            IsTiming = temp[3] == "1";
            OpenTime = temp[4];
            AllowReg = temp[5] == "1";
            OnlyEmail = temp[6] == "1";
            CheckReg = temp[7] == "1";
            PageCount = Jumbot.Common.Validator.StrToInt(temp[8].ToString(), 20);
            Url = temp[9];
            Keywords = temp[10];
            Description = temp[11];
            IsHtml = temp[12] == "0";
            //Dir = temp[13];
            Dir = Jumbot.Common.DirFile.AppPath();
            StaticExt = temp[14].ToLower();
            ICP = temp[15];
            TitleTail = Jumbot.Common.XmlCOM.ReadConfig(Dir + "_data/config/config", "TitleTail");
            UserItem = Jumbot.Common.XmlCOM.ReadConfig(Dir + "_data/config/user", "UserItem");
            WriterItem = Jumbot.Common.XmlCOM.ReadConfig(Dir + "_data/config/user", "WriterItem");
            Service = Jumbot.Common.XmlCOM.ReadConfig(Dir + "_data/config/config", "Service");
            AdminGroupId = Jumbot.Common.Validator.StrToInt(Jumbot.Common.XmlCOM.ReadConfig(Dir + "_data/config/user", "AdminGroupId"), 5);
            CookieDomain = Jumbot.Common.XmlCOM.ReadConfig(Dir + "_data/config/cookies", "Domain");
            CookiePath = Jumbot.Common.XmlCOM.ReadConfig(Dir + "_data/config/cookies", "Path");
            CookiePrev = Jumbot.Common.XmlCOM.ReadConfig(Dir + "_data/config/cookies", "Prev");
            CookieKeyCode = Jumbot.Common.XmlCOM.ReadConfig(Dir + "_data/config/cookies", "KeyCode");
            UrlReWriter = (Jumbot.Common.Validator.StrToInt(Jumbot.Common.XmlCOM.ReadConfig("~/_data/config/config", "UrlReWriter"), 0) == 1);
            ExecuteSql = (Jumbot.Common.Validator.StrToInt(Jumbot.Common.XmlCOM.ReadConfig("~/_data/config/config", "ExecuteSql"), 0) == 1);
            CreatePages = Jumbot.Common.Validator.StrToInt(Jumbot.Common.XmlCOM.ReadConfig(Dir + "_data/config/config", "CreatePages"), 20);
            ForumPath = Jumbot.Common.XmlCOM.ReadConfig(Dir + "_data/config/api", "ForumPath");
            ForumUrl = Jumbot.Common.XmlCOM.ReadConfig(Dir + "_data/config/api", "ForumUrl");
            if (ForumPath != "")//表示整合
            {
                LoginUrl = Jumbot.Common.XmlCOM.ReadConfig(Dir + "_data/config/api", "LoginUrl");
                LogoutUrl = Jumbot.Common.XmlCOM.ReadConfig(Dir + "_data/config/api", "LogoutUrl");
                RegisterUrl = Jumbot.Common.XmlCOM.ReadConfig(Dir + "_data/config/api", "RegisterUrl");
                GetPasswordUrl = Jumbot.Common.XmlCOM.ReadConfig(Dir + "_data/config/api", "GetPasswordUrl");
            }
            else
            {
                LoginUrl = "passport/login.aspx";
                LogoutUrl = "passport/logout.aspx";
                RegisterUrl = "passport/register.aspx";
                GetPasswordUrl = "passport/getpassword.aspx";
            }
            DebugKey = Jumbot.Common.XmlCOM.ReadConfig(Dir + "_data/config/config", "DebugKey");
            if (DebugKey.Length == 0) DebugKey = "4cae-34b2-12ac-67ae";
        }
    }
}
